package com.senmo.app;

import com.senmo.data.DeviceDataProvider;
import com.senmo.manager.AccountManager;
import com.senmo.model.User;
import com.senmo.model.event.LoginStateChangeEvent;
import com.senmo.request.VolleyManager;
import com.senmo.video.SenmoVideo;

import de.greenrobot.event.EventBus;
import lx.af.base.AbsBaseApp;
import lx.af.utils.PathUtils;
import lx.af.utils.SystemUtils;
import lx.af.utils.log.Log;

/**
 * Created by liuxu on 15-6-11.
 *
 */
public class App extends AbsBaseApp {

    @Override
    public void onCreate() {
        super.onCreate();
        VolleyManager.init(this);
        PathUtils.setSdRoot("SenMo");
        EventBus.getDefault().register(this);
    }

    public void onEvent(LoginStateChangeEvent event) {
        Log.d("liuxu", "login state changed, login: " + event.isLogin());
        if (event.isLogin()) {
            DeviceDataProvider.getInstance().getDeviceList(true, null);
            User user = AccountManager.getInstance().getUser();
            SenmoVideo.init(user.phone, SystemUtils.getVersionName());
        } else {
            DeviceDataProvider.getInstance().clear();
        }
    }

}
